package com.server.common.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;

public class PDF_2_Image_Util {
	
	public static final int PPT_SAVEAS_JPG = 17;

	public static int pdf2Image(File sourceFile, File destFile) {  
		  
        // 目标路径不存在则建立目标路径  
        if (!destFile.exists())  
        	destFile.mkdirs();  
  
        // 源文件不存在则返回 -1  
        if (!sourceFile.exists())  
            return -1;  
  
        String tools_HOME = "C:\\PDF2JPG\\PDFtoJPG真正无水印";//PDFtoJPG的路径。  
        try {  
            String command =  tools_HOME + "\\PDFtoJPG.exe  -i " + sourceFile + " -o "  
                    + destFile;  
            Process pro = Runtime.getRuntime().exec(command);  
  
            BufferedReader bufferedReader = new BufferedReader(  
                    new InputStreamReader(pro.getInputStream()));  
            while (bufferedReader.readLine() != null) {  
  
            }  
            pro.waitFor();  
            return pro.exitValue();  
        } catch (InterruptedException e) {  
            e.printStackTrace();  
        } catch (IOException e1) {  
            e1.printStackTrace();  
        }  
  
        return 1;  
    }  
	
    public static void main(String[] args) {  
    	File inputFile = new File("D:/PPT_test/经典JAVA教程(入门到精通)(1).ppt");
		File outputFile = new File("D:/PPT_test/经典JAVA教程(入门到精通)(1).pdf");
		PPT_2_PDF_Util.ppt2PDF(inputFile, outputFile);
        String sourcePath = "d:/PPT_test/经典JAVA教程(入门到精通)(1).pdf";  
        String destPath = "d:/PPT_test/经典JAVA教程(入门到精通)(1)";  
        System.out.println(new PDF_2_Image_Util().pdf2Image(new File(sourcePath),  
        		new File(destPath)));  
    }  
}
